import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

import '../../../common/utils/shortcut.dart';
import '../../../common/utils/show.dart';
import '../../../config.dart';
import '../../widget/dialog/my_textfield_dialog.dart';
import 'common/common.dart';
import 'my_debug_page.dart';

export 'my_debug_page.dart';
export 'widget/log_widget.dart';
export 'common/common.dart';

Future<bool> openDeveloperMode() async {
  if (developerMode) {
    Show.info("已经是开发者模式");
    return developerMode;
  }
  final ret = await const MyTextFieldDialog(
    title: "进入开发者模式",
    hintText: "开发者密码",
    obscureText: true,
  ).show(barrierDismissible: false);
  if (ret != null && ret == JmConfig.developerPassword) {
    developerMode = true;
    Show.info("进入开发者模式");
  } else {
    if (ret != null) {
      Show.error("密码错误");
    }
  }
  return developerMode;
}

void gotoDeveloperPage({Widget? child, bool ignorePassword = false}) async {
  if (!ignorePassword && !developerMode && !kDebugMode) {
    //Show.info("请先进入开发者模式");

    if (!await openDeveloperMode()) {
      return;
    }
  }

  goto(() => MyDebugPage(
        child: child,
      ));
}
